




#ifndef _VIN_H264_NAL_UNIT_H_
#define _VIN_H264_NAL_UNIT_H_

#include <iostream>
#include "VinH264PictureUnits.h"
#include "VinDefines.h"


enum naluTypes {

    kNalUnitTypeIDR    = 5,
    kNalUnitTypeNonIDR = 1,
    kNalUnitTypeSPS    = 7,
    kNalUnitTypePPS    = 8,
    kNalUnitTypeSEI    = 6
};

typedef struct nalHeader {

    UInt8 nalUnitType       : 5;
    UInt8 nalUnitRefIdc     : 2;
    UInt8 nalForbiddenBit   : 1;
} NAL_HEADER, *PNAL_HEADER;

class nalUnit {
public:
    PNAL_HEADER theNalHeader;

    UInt8* nalPayload;
    UInt32 nalLength;
};


class VinBitstreamIO;

class VinNalUnit
{
public:

    // Default constructor/destructor.
    VinNalUnit ();
    ~VinNalUnit ();

    // Get the next NAL unit in the bitstream.
    nalUnit* GetNextNalUnit(UInt8* bitstream);

    void ParseNalUnit (nalUnit* theNalUnit);

    void ParseSPSNal (nalUnit* theNalUnit);
    void ParsePPSNal (nalUnit* theNalUnit);
    void ParseIDRNal (nalUnit* theNalUnit);
    void ParsePTypeNal (nalUnit* theNalUnit);
private:
};



static class VinStreamParameters {

public:

    // Function to parse the SPS NAL unit.
    UInt32 parseSPSNalUnit (nalUnit* nal);

    // Function to activate SPS.
    void activateSPS (UInt32 index);

    // Function to parse PPS Nal unit.
    UInt32 parsePPSNalUnit (nalUnit* nal);

    // Function to activate PPS.
    void activatePPS (UInt32 index);

    SPSInfo* activeSPS;
    PPSInfo* activePPS;

private:
    std::vector<SPSInfo*> SPSArray;
    std::vector<PPSInfo*> PPSArray;
};

#endif